#ifndef _NAMETOK_H_
#define _NAMETOK_H_
#include "ast/NameTokType.h"
#include "ast/nameContextType.h"
#include "AstTypes.h"
class IVisitor;
class NameTok;
typedef QSharedPointer<NameTok> NameTokPtr;

class NameTok: public NameTokType
{
public:
    explicit NameTok(const QString& id, int ctx, int nodeId=-1);
    virtual ~NameTok();
    
    
    QString id();
    void setId(const QString& id);
    
    int ctx();
    void setCtx(int ctx);
    
    
    virtual Ast::AstTypes type() const;
    virtual QString toString() const;
    virtual void accept(IVisitor* visitor, const SimpleNodePtr& node);
    virtual void traverse(IVisitor* visitor);
private:
    QString _id;
    int _ctx;
};



typedef QListIterator<NameTokPtr> NameTokPtrListIterator;

class NameTokList: public QList<NameTokPtr>
{
public:
    inline NameTokList() { }
    inline explicit NameTokList(NameTokPtr i) { append(i); }
    inline NameTokList(const NameTokList &l) : QList<NameTokPtr>(l) { }
    inline NameTokList(const QList<NameTokPtr> &l) : QList<NameTokPtr>(l) { }

    inline NameTokList operator+(const NameTokList &other) const
    { NameTokList n = *this; n += other; return n; }
    inline NameTokList &operator<<(NameTokPtr it)
    { append(it); return *this; }
    inline NameTokList &operator<<(const NameTokList &l)
    { *this += l; return *this; }

    QString toString() const
    {
        QString str("NameTokList(");
        foreach(NameTokPtr it, *this){
            if (it != NULL){
                str += it->toString()+",";
            }
        }
        str += ")";
        return str;
    }

    void traverse(IVisitor* visitor)
    {
        foreach(NameTokPtr it, *this){
            if (it != NULL){
                it->accept(visitor, it);
            }
        }
    }
};



#endif